﻿using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using System.ComponentModel;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Reference to a control which can used to specify which controls need to be transferred as part of a form submission.
	/// </summary>
	[ParseChildren(true)]
	[PersistChildren(false)]
	[ToolboxData("<t:ControlReference runat=\"server\" ControlId=\"\" />")]
	public class ControlReference : BaseControlReference
	{
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		public ControlReference()
		{
		}
		/// <summary>
		/// Ctor which sets the target and adds the new reference to the control tree.
		/// </summary>
		/// <param name="control"></param>
		public ControlReference(Control control)
		{
			if (control.get_TPage() != null)
				control.get_TPage().SpecialContainer.Controls.Add(this);
			else if (control.Page != null)
				control.Page.Controls.Add(this);

			this.ControlId = control.UniqueID;
		}
		/// <summary>
		/// Ctor which adds the new reference to the specified container and sets the reference ID to the specified control ID.
		/// </summary>
		/// <param name="container"></param>
		/// <param name="controlId"></param>
		public ControlReference(Control container, string controlId)
		{
			container.Controls.Add(this);
			this.ControlId = controlId;
		}
		/// <summary>
		/// Copy ctor.
		/// </summary>
		/// <param name="gcr"></param>
		public ControlReference(BaseControlReference gcr)
		{
			this.ControlId = gcr.ControlId;
			this.Value = gcr.Value;
			this.Properties = gcr.Properties;
			this.PropertiesMode = gcr.PropertiesMode;
			this.SendAs = gcr.SendAs;

			gcr.Parent.Controls.Add(this);
		}
		#endregion
		#endregion
	}
}